package com.ruoyi.project.module.joinus.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.joinus.domain.Joinus;
import com.ruoyi.project.module.joinus.service.IJoinusService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * JoinUsController
 * 
 * @author javen
 * @date 2020-12-24
 */
@Controller
@RequestMapping("/module/joinus")
public class JoinusController extends BaseController
{
    private String prefix = "module/joinus";

    @Autowired
    private IJoinusService joinusService;

    @RequiresPermissions("module:joinus:view")
    @GetMapping()
    public String joinus()
    {
        return prefix + "/joinus";
    }

    /**
     * 查询JoinUs列表
     */
    @RequiresPermissions("module:joinus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Joinus joinus)
    {
        startPage();
        List<Joinus> list = joinusService.selectJoinusList(joinus);
        return getDataTable(list);
    }

    /**
     * 导出JoinUs列表
     */
    @RequiresPermissions("module:joinus:export")
    @Log(title = "JoinUs", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Joinus joinus)
    {
        List<Joinus> list = joinusService.selectJoinusList(joinus);
        ExcelUtil<Joinus> util = new ExcelUtil<Joinus>(Joinus.class);
        return util.exportExcel(list, "joinus");
    }

    /**
     * 新增JoinUs
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存JoinUs
     */
    @RequiresPermissions("module:joinus:add")
    @Log(title = "JoinUs", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Joinus joinus)
    {
        return toAjax(joinusService.insertJoinus(joinus));
    }

    /**
     * 修改JoinUs
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Joinus joinus = joinusService.selectJoinusById(id);
        mmap.put("joinus", joinus);
        return prefix + "/edit";
    }

    /**
     * 修改保存JoinUs
     */
    @RequiresPermissions("module:joinus:edit")
    @Log(title = "JoinUs", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Joinus joinus)
    {
        return toAjax(joinusService.updateJoinus(joinus));
    }

    /**
     * 删除JoinUs
     */
    @RequiresPermissions("module:joinus:remove")
    @Log(title = "JoinUs", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(joinusService.deleteJoinusByIds(ids));
    }
}
